home *** CD-ROM | disk | FTP | other *** search
- // HTBIntegerSum
-
- // example for calling _stdcall dll from _cdecl dll
-
- // High Tech BASIC, Copyright (C) TransEra Corp 2000, All Rights Reserved.
-
-
-
- #include <windows.h>
-
-
- typedef int (WINAPI * lpIntSum)(int,int); // standard call type def for function
-
-
- lpIntSum fpIntSum = NULL; // used to hold function pointer
-
- HINSTANCE hIntSum; // used to hold handle to DLL
-
-
- extern "C"
- {
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- // Function name : InitDLL
- // Description : initalize function pointer for IntegerSum function in IntegerSum.dll
- // Return type : BOOL
- BOOL InitDLL()
- { BOOL result = TRUE;
-
- hIntSum = LoadLibrary("IntegerSum.dll"); // load DLL
-
- if (hIntSum != NULL) // if load did not fail
- { fpIntSum = (lpIntSum)GetProcAddress(hIntSum,"IntegerSum"); // get pointer to function
-
- if (fpIntSum == NULL) // if pointer is bad
- { result = FALSE; // set to return an error
- }
- }
- else
- { result = FALSE; // if load failed set to return an error
- }
-
- return(result);
- }
-
-
- ///////////////////////////////////////////////////////////////////////////////////////////////////////
-
-
-
- // Function name : IntegerSum
- // Description : return the sum of two ints
- // Return type : int
- // Argument : int val1
- // Argument : int val2
- int _cdecl Integersum(int val1, int val2)
- { if (fpIntSum == NULL) // if we have no function pointer yet
- { BOOL result = InitDLL(); // go load DLL and get one
-
- if (!result) // if failed getting function pointer
- { MessageBox(NULL,"Error Loading __stdcall DLL","Error",MB_OK);
- return(0); // return a zero -- zero could also be a vaild sum!!!
- }
- }
-
- return(fpIntSum(val1,val2)); // Call standard Call function and return result
- }
-
-
-
- } // end extern "C"